$(document).ready(function() {	
	$( 'textarea#pcontent' ).ckeditor();
	$.validator.messages.required = field_required;
	$("#frmEdit").validate({
		errorClass		: 'error',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		ignore			: "input[type='text']:hidden",
		rules: {							
			pname:{
				required			: true,
				minlength			: VL_NAME_MINLENGTH		
			},
			pcode: {
				required			: true,
				minlength			: VL_NAME_MINLENGTH
			},
			pimage: {					
				validateImgFormat	: true,
				validateImgSize		: true
			},
			pcontent: {
				minlengthContent	: true,
			},
			pprice: {
				required			: true,
			}
		},
		
		messages: {					
			pname:{
				required			: name_required,
				minlength			: name_minlength
			},
			pcode: {
				required			: code_required,
				minlength			: code_minlength
			},
			pimage: {					
				validateImgFormat	: image_format,
				validateImgSize		: image_size
			},
			pcontent: {
				minlengthContent	: content_minlength,
			},
			pprice: {
				required			: price_required
			}
		},
		errorPlacement: function(label, element) {
			var id 			= element.attr('id');	
			var cls			= $('#' + id).attr('class');
			if(cls != undefined) {
				cls			= cls.replace(' required','');
			}			
			if(id == "pcontent") {			
				label.insertAfter($('#cke_pcontent'));
			}else if(cls == 'radio' || cls == 'checkbox'){
				var parentId	= $('#' + id).attr('parent-id');	
				var msg			= $('#' + id).attr('message-error');	
				if(msg != '') {
					label.html(msg).insertAfter($('#ul' + parentId));	
				} else {
					label.insertAfter($('#ul' + parentId));	
				}
			}else if(cls == 'text' || cls == 'textarea' || cls == 'select') {
				var msg	= $('#' + id).attr('message-error');	
				if(msg != '') {
					label.html(msg).insertAfter($('#' + id));		
				} else {
					label.insertAfter($('#' + id));		
				}
			}else {
				label.insertAfter($('#' + id));				
			}			
		}/*,
		submitHandler: function(form) {	
			
			form.submit();
		}*/
	});	
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == '') {
			return true;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == '') {
			return true;
		}
		return validateImgSize('pimage', IMAGE_SIZE);
	});	
	$.validator.addMethod('minlengthContent', function() {
		var strContent	= stripTags($('#pcontent').val(), 1);			
		if(strContent != '' && strContent.length < VL_CONTENT_MINLENGTH)
			return false;		
		return true;	
	});	
	$('#pps_start').datepicker({showButtonPanel: true});
	$('#pps_start').datepicker('option', {dateFormat: 'dd/mm/yy'});
	$('#pps_end').datepicker({showButtonPanel: true});
	$('#pps_end').datepicker('option', {dateFormat: 'dd/mm/yy'});
	$('#pnew_sd').datepicker({showButtonPanel: true});
	$('#pnew_sd').datepicker('option', {dateFormat: 'dd/mm/yy'});
	$('#pnew_ed').datepicker({showButtonPanel: true});
	$('#pnew_ed').datepicker('option', {dateFormat: 'dd/mm/yy'});
});
